package rpg.client.model;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Dialog {
    public static class Builder {
        private String id = "";

        private String actorId = "";
        private String text = "";
        private Mode mode = Mode.TALKING;
        private final List<DialogResponse> responses = new ArrayList<DialogResponse>();

        private boolean nullInstance = false;

        public Builder() {
            super();
        }

        public Builder actorId(String s) {
            actorId = s;
            return this;
        }

        public Dialog build() {
            return new Dialog(this);
        }

        public Builder id(String s) {
            id = s;
            return this;
        }

        public Builder makeNull() {
            nullInstance = true;
            return this;
        }

        public Builder mode(Mode m) {
            mode = m;
            return this;
        }

        public Builder response(DialogResponse dr) {
            responses.add(dr);
            return this;
        }

        public Builder text(String s) {
            text = s;
            return this;
        }
    }

    public enum Mode {
        TALKING, NARRATION, MOBILE;
    }

    private final String id;
    private final Mode mode;

    private final String actorId;
    private final String text;

    private final List<DialogResponse> responses;

    private Dialog(Builder b) {
        super();
        actorId = b.nullInstance ? "" : b.actorId;
        id = b.id;
        text = b.nullInstance ? "" : b.text;
        mode = b.nullInstance ? Mode.TALKING : b.mode;
        responses = b.nullInstance ? DialogResponse.EMPTY_LIST : Collections.unmodifiableList(b.responses);
    }

    public String getActorId() {
        return actorId;
    }

    public String getId() {
        return id;
    }

    public Mode getMode() {
        return mode;
    }

    public List<DialogResponse> getResponses() {
        return responses;
    }

    public String getText() {
        return text;
    }

    @Override
    public String toString() {
        return "Dialog: " + id + " (" + actorId + ") " + text;
    }
}
